<template>
	<view>
		<view v-for="item in newSubjectChoices" :key="item.choiceId">
			<view :class="[item.showClass]">
				<text>{{item.choiceId}}、</text>
				<text class="content-opt">{{item.choiceDesc}}</text>
			</view>
			<auto-img v-if="item.choiceType=='2'" :src="item.contentUrl"></auto-img>
			<audio v-if="item.choiceType=='4'" :src="item.contentUrl"></audio>
			<video v-if="item.choiceType=='3'" :src="item.contentUrl"></video>
		</view>
	</view>
</template>

<script>
	import {
		isEmpty
	} from '@/utils/index'
	import AutoImg from '@/pages/exam/fragments/AutoImg.vue';
	export default {
		components: {
			AutoImg
		},
		props: {
			subject: {
				type: Object,
				default: function() {
					return {}
				}
			},
		},
		computed: {
			selectChoice() { //学生答案
				let selectChoice = this.subject.choice
				return isEmpty(selectChoice) ? '' : selectChoice;
			},
			answer() {
				let answer = this.subject.answer;
				return isEmpty(answer) ? '' : answer;
			},
			newSubjectChoices() {
				if(isEmpty(this.subject.subjectChoices)){
					return [];
				}
				const {
					selectChoice
				} = this;
				if (isEmpty(this.answer)) return this.subjectChoices;
				this.subject.subjectChoices.forEach(item => {
					// 正确答案
					if (this.answer.indexOf(item.choiceId) > -1) {
						if(isEmpty(selectChoice)){//用户未答,正确答案
							item.showClass = 'content-itemcnot'
						}else{
							//用户选了，渲染为正确
							if (selectChoice.indexOf(item.choiceId) > -1) {
								item.showClass = 'content-itemc'
							} else { //用户没选，渲染为半正确
								item.showClass = this.subject.type == '3' ? 'content-itemcnot' : 'content-itemc'
							}
						}
					} else { //错误答案
						//用户选了，渲染为错误
						if (selectChoice.indexOf(item.choiceId) > -1) {
							item.showClass = 'content-iteme'
						} else { //用户没选，渲染为正常
							item.showClass = 'content-item'
						}
					}
				})
				return this.subject.subjectChoices;
			}
		}
	}
</script>

<style lang="scss" scoped>
	.content {
		margin: 20upx;
		font-size: 28upx;
		border-radius: 8rpx;
		box-shadow: 0 0 10upx #eaeaea;
		padding: 30upx 30upx;

		&-block {
			margin-bottom: 40upx;
		}

		&-type {
			color: #5ea1f8;
			font-weight: bold;
		}

		&-sub {
			color: #000;
			font-weight: bold;
		}

		&-item {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #f4f6f8;
			border-radius: 8rpx;
			color: #000;
		}

		&-itemc {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #5ea1f8;
			color: #fff;
			border-radius: 8rpx;
		}
		&-itemcnot {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			font-size: 26upx;
			width: 630upx;
			background: #5ea1f8;
			color: #fff;
			border-radius: 8rpx;
			border: 4upx solid #f1685d;
		}

		&-iteme {
			display: flex;
			flex-direction: row;
			justify-content: flex-start;
			align-items: flex-start;
			margin: 20upx 0;
			padding: 30upx 20upx;
			width: 630upx;
			background: #f1685d;
			color: #fff;
			border-radius: 8rpx;
			color: #fff;
		}

		&-ico {
			display: inline-block;
			width: 40upx;
			height: 40upx;
			border: 1px solid #377cfd;
			border-radius: 50%;
			margin-right: 30upx;
			color: #377cfd;
			text-align: center;
			color: #377cfd;
		}

		&-icoc {
			display: inline-block;
			width: 40upx;
			height: 40upx;
			border: 1px solid #377cfd;
			border-radius: 50%;
			margin-right: 30upx;
			text-align: center;
			color: #fff;
			background: #377cfd;
		}

		&-icoe {
			display: inline-block;
			width: 40upx;
			height: 40upx;
			border: 1px solid #ba0909;
			border-radius: 50%;
			margin-right: 30upx;
			text-align: center;
			color: #fff;
			background: #ba0909;
		}

		&-opt {
			/*display: inline-block;*/
			/*line-height: 80upx;*/
			line-height: 1.5;
		}

	}
</style>
